﻿/*

utilisation : attachMovie
requis : MovieClip mcCheck , MovieClip mcFond
exemple :

var rbs = new net.streampower.forms.RadioButtonSet()
rbs.setLabel("label de element de formulaire")//(facultatif)
rbs.addRadioButton(a)
rbs.addRadioButton(b)
a.value = "ml"
b.value = "vcvc"

rbs.setValue("ml");// valeur par defaut

a.onRelease2 = function//pour lancer une fonction lors du click

*/

package fab.forms.fields 
{
	import fab.forms.fields.Element;
	import flash.display.Sprite;
	/**
	 * ...
	 * @author fab
	 */
	public class ClipRadioButton extends Element
	{
		private var mcCheck,mcFond:MovieClip;	
		private var checked:Boolean;
		private var __value:Object;
		private var __rbSet:RadioButtonSet;
		
		var onRelease2:Function;
		

		
		public function RadioButton( sp:Sprite=null)
		{
			if ( sp )
			{
				sp_Tool_pileur = sp;
				sp.rotation = -90;
				x = sp.x - 45;
				y = sp.y + 80;
				sp.x = 0;
				sp.y = 0;				
			}
			else {
				sp_Tool_pileur = new Sprite();
				sp_Tool_pileur.graphics.beginFill(0xFF0000,.5);
				sp_Tool_pileur.graphics.drawRect( -20, -20, 40, 40);				
				//x = _x;
				//y = _y;
			}
			
			
			this.check(false);
			this.mcFond.onRelease = function(){
				this._parent.__rbSet.setValue(this._parent.__value, this._parent);
			}
		}	
		
		public function check(pValue:Boolean, pClip:RadioButton):void
		{
			this.checked = pValue;
			this.mcCheck._visible = pValue;
			if(this.onRelease2!=undefined && pClip==this){
				this.onRelease2();
			}
		}
		
		public function get value():* {
			return this.__value;
		}

		public function set value(__value:Object):void {
			this.__value = __value;
		}

		public function get rbSet():RadioButtonSet {
			return __rbSet;
		}

		public function set rbSet(__rbSet:RadioButtonSet):void {
			this.__rbSet = __rbSet;
		}	
	}
}